package com.cxg.fairy.util;

import android.content.Context;
import android.graphics.Color;

import com.yanyusong.y_divideritemdecoration.Y_Divider;
import com.yanyusong.y_divideritemdecoration.Y_DividerBuilder;
import com.yanyusong.y_divideritemdecoration.Y_DividerItemDecoration;

/**
 * Created by Administrator on 2018/2/6.
 */

public class MyADDividerItemDecoration extends Y_DividerItemDecoration {

    int vItemCount = 0;

    public MyADDividerItemDecoration(Context context) {
        super(context);
    }

    public MyADDividerItemDecoration(Context context, int vItemCount) {
        super(context);
        this.vItemCount = vItemCount;
    }

    @Override
    public Y_Divider getDivider(int itemPosition) {
        Y_Divider divider = null;

        if (itemPosition == 0) {
            divider = new Y_DividerBuilder()
                    .setBottomSideLine(true, Color.parseColor("#EAEAEA"), 5, 0, 0)
                    .create();

        } else if (itemPosition > 0 && itemPosition <= vItemCount) {
            divider = new Y_DividerBuilder()
                    .setBottomSideLine(true, Color.parseColor("#EAEAEA"), 2, 0, 0)
                    .create();
        } else if (itemPosition > vItemCount) {

            switch ((itemPosition - vItemCount + 1) % 2) {
                case 0:
                    //每一行第一个显示rignt和bottom
                    divider = new Y_DividerBuilder()
                            .setRightSideLine(true, Color.parseColor("#EAEAEA"), 1, 0, 0)
                            .setBottomSideLine(true, Color.parseColor("#EAEAEA"), 2, 0, 0)
                            .create();
                    break;
                case 1:
                    //第二个显示Left和bottom
                    divider = new Y_DividerBuilder()
                            .setLeftSideLine(true, Color.parseColor("#EAEAEA"), 1, 0, 0)
                            .setBottomSideLine(true, Color.parseColor("#EAEAEA"), 2, 0, 0)
                            .create();
                    break;
                default:
                    divider = new Y_DividerBuilder()
                            .setLeftSideLine(false, Color.parseColor("#EAEAEA"), 1, 0, 0)
                            .create();
                    break;
            }

        }

        return divider;
    }
}
